<?php
include_once("./Db_pdo.class.php");
header("content-type:text/html;charset=utf-8"); 
ini_set('date.timezone','Asia/Shanghai');
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
/**
* 
*/
class digui
{
    public $params;
    
	function __construct(){
        // $this->params = unserialize(file_get_contents('fx_user.txt'));
    }
	

    public function get_parent_id($uid){
        $params = $this->params;
        
        // print_r($params);
        $pids = '';

        $result= $this -> filterArray($params,'uid','=',$uid);
        // print_r($result);
        if($result){
            $parent_id = $result[0]['pid'];

            if( $parent_id != '' && $parent_id!==$uid){
                $pids .= $parent_id;
                $npids = $this->get_parent_id($parent_id);
                if(isset($npids)&&$npids>0){
                    $pids .= ','.$npids;
                }
            }
        }
        //再来排序
        
        //除开为0
        // $count = count($pids);
        // if(!$pids[$count]){
        //     unset($pids[$count]);
        // }
        // foreach ($ as $key => $value) {
        //     # code...
        // }
        // print_r($pids[);
        return $pids;
    }
    public function  get_agent($arr){ 
        global $DB;
        if(count($arr)<=0){
            return array();
        }
       
        $sqls = "
                SELECT
                a.cxhname,
                a.mobile,
                a.realname,
                b.uex_areaName,
                b.uex_cityNname,
                b.uex_provinceName
            FROM
                ims_ewei_shop_member AS a
            INNER JOIN ims_cxh_user_ex AS b ON b.member_id = a.id
            WHERE
                b.member_id = ".$arr['0']."
            AND a.cxhname LIKE 'DLS%'
        ";
        $user = $DB->new_query($sqls);
        $user = $user->fetchAll(PDO::FETCH_ASSOC);
       
        $result ='';
        if(count($user)>0){
           
            return $user;
           
        }else{
            
            if(count($arr)<=1){
              
                return array();
            }else{
                
                array_shift($arr);
                $ss = $this->get_agent($arr);
                if(count($ss)>0){
                    return $ss;
                }else if(count($ss)==0){
                    return false;
                }
               
            }
        }
        
        
    }

    function genTree5($items) { 
        foreach ($items as $item) {
            $items[$item['pid']]['son'][$item['uid']] = &$items[$item['uid']]; 
        }
        return isset($items[0]['son']) ? $items[0]['son'] : array(); 
    } 
      
   
    function genTree9($items) {
        $tree = array(); //格式化好的树
        foreach ($items as $item)
            if (isset($items[$item['pid']]))
                $items[$item['pid']]['son'][] = &$items[$item['id']];
            else
                $tree[] = &$items[$item['id']];
        return $tree;
    }
  
    function filterArray($arr,$filter_col,$filter_type,$val1 = '',$val2 = ''){
        $return = array();
        if(!empty($arr)){
            foreach($arr as $k=>$v){
                switch($filter_type){
                    case 'eq':
                    case '=' :
                        if(is_array($val1)){
                            if(in_array($v[$filter_col],$val1)){
                                $return[] = $v;
                            }
                        }else{
                            if($v[$filter_col]==$val1){
                                $return[] = $v;
                            }
                        }
                        break;
                    case 'neq':
                    case '!=' :
                        if(is_array($val1)){
                            if(!in_array($v[$filter_col],$val1)){
                                $return[] = $v;
                            }
                        }else{
                            if($v[$filter_col]!=$val1){
                                $return[] = $v;
                            }
                        }
                        break;
                    case 'gt':
                    case '>':
                        if($v[$filter_col]>$val1){
                            $return[] = $v;
                        }
                        break;
                    case 'lt':
                    case '<':
                        if($v[$filter_col]<$val1){
                            $return[] = $v;
                        }
                        break;
                    case 'egt':
                    case '>=':
                        if($v[$filter_col]>=$val1){
                            $return[] = $v;
                        }
                        break;
                    case 'elt':
                    case '<=':
                        if($v[$filter_col]<=$val1){
                            $return[] = $v;
                        }
                        break;
                    case 'between':
                        if($v[$filter_col]>$val1&&$v[$filter_col]<=$val2){
                            $return[] = $v;
                        }
                        break;
                    case 'like':
                        $val1 = str_replace('%','',$val1);
                        $rs = stristr($v[$filter_col],$val1);
                        if(!empty($rs)){
                            $return[] = $v;
                        }
                        break;
                }
            }
        }
        return $return;
    }
    
    function sortArray($arr,$sort_col,$sort_type){
        if(!empty($arr)){
            $sort_flag = array();
            foreach($arr as $k=>$v){
                $sort_flag[] = $v[$sort_col];
            }
            array_multisort($sort_flag,$sort_type,$arr);
        }
        return $arr;
    }



   

   
}

?>